package com.shop.admin.job;


import com.shop.admin.service.pink.StoreOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CheckOrderJob {

    @Autowired
    private StoreOrderService storeOrderService;

    @Async("checkOrderScheduler")
    @Scheduled(cron = "0 */1 * * * ?")
    public void checkNeedPayOrder(){
        log.info("--- 同步待支付订单开始 ---");

        int timeoutMin = -30;   // 30分钟
        int timeoutEnd = -1;   // 1分钟
        int limit = 500;        // 处理行数

        storeOrderService.checkNeedPayOrder(timeoutMin, timeoutEnd, limit);

        log.info("--- 同步待支付订单结束 ---");
    }

    @Async("checkOrderScheduler")
    @Scheduled(cron = "0 55 2,4,6,8,10,12,13,16,18,20,21,23 * * ?")
    public void checkOrderSchedulerSup(){
        log.info("--- 补单同步待支付订单开始 ---");

        int timeoutMin = -360;   // 2天前
        int timeoutEnd = -1;   // 10分钟之前
        int limit = 30000;        // 处理行数

        storeOrderService.checkNeedPayOrder(timeoutMin, timeoutEnd, limit);

        log.info("--- 补单同步待支付订单结束 ---");

    }

}
